Skip to content

feat(agents): Agent 资源库统一管理指令、技能、MCP 服务器和 Hooks,并逐条列出调用(API-45 0 内补充) - #223

Merged
xiaoyumuxi merged 4 commits into
mainfrom
feat/agent-configuration-library
Nov 28, 2026
Merged

xiaoyumuxi merged 4 commits into
mainfrom
feat/agent-configuration-library

Conversation

@xiaoyumuxi

Copy link
Copy Markdown
Contributor

概述 / Summary

API-45(Agent)的 agents 0 内补充,给桌面端 1lck/Lithe-IDEA#2492 的 AI 管理窗口 用。用户要在一个独立窗口里统一管理各个 Agent 最常用的四类配置:MCP 服务器、技能、Hooks、指令。可以按 Agent 逐个开关,Agent 自己装的内容只读显示,也可以导入和删除。Agent 的名称和图标都由插件声明(displayName、icon),Core 和宿主不保存任何 Agent 的名称、图标或配置格式。

做法分三层:

  1. 插件声明 CLI 把配置放在哪里:清单 agents[] 新增可选 configuration {instructions?, skills?, files?, read?, edit?},并新增权限 agents.configuration。
    • instructions 是 CLI 读的用户指令文件,skills 是用户技能目录,两者都由 Core 直接读写。
    • files 是最多 8 个保存 MCP 服务器和 Hooks 的 CLI 配置文件({id, roots}),文件格式只有插件后端知道。
    • 路径写法同会话来源的根目录:每处 1–4 个候选,${userHome} 或 ${env:NAME} 后至少一段。
    • read、edit 是普通插件函数:read 回答 litheAgentConfiguration 快照,环境变量和请求头只给名称;edit 只改 Core 给的暂存副本,并保留文件里的其他内容。
  2. Core 保存资源库并负责写回:资源库(MCP 服务器、Hooks、指令集、技能)是 Lithe 自己的数据,放在平台应用数据目录。
    • Core 对比资源库和每个 Agent 的实际配置,给出 on / off / conflict / unsupported。
    • 用户选中一项改动后,Core 只把这一项写进一个 Agent:
      • 指令文件整份写成“当前指令集 + 该 Agent 的附加文字”;
      • 技能用符号链接;
      • MCP 服务器和 Hooks 交给插件 edit 改暂存副本,Core 校验后原子替换,期间文件被改动就拒绝。
  3. 宿主只画界面:agentLibrary.* 命令都是平台宿主命令;save、apply、importSkill、removeSkill 只接受用户发起的请求,插件不能替用户改资源库或 Agent 配置。

同一 PR 还有 agentSessions.calls(提交 2148493),给 AI 管理窗口的“用量 → 请求”页用:按时间倒序分页列出 scan 报告的每一次调用,带 Core 算出的费用、缓存命中率和速度。

没有新增能力版本、协议版本或插件宿主方法。旧 Core 以 plugin.manifest.invalid 拒绝声明了 configuration 或 agents.configuration 的清单,也不回答 agentLibrary.* 和 agentSessions.calls。

方法与命令 / Methods and commands

没有新增插件宿主方法或宿主通知。下面都是平台宿主命令(宿主调用 Core),以及插件后端按清单声明实现的普通函数:

原计划编号 方法 用途
API-45 agentLibrary.configure(平台宿主命令) 在平台应用数据目录打开资源库,传入 userHome 和配置路径用到的环境变量
API-45 agentLibrary.read(平台宿主命令) 读资源库和每个可配置 Agent 的指令、技能、MCP 服务器与 Hooks,带修订号和逐项状态
API-45 agentLibrary.save(平台宿主命令) 修订号未变时替换用户编辑过的资源库
API-45 agentLibrary.apply(平台宿主命令) 把用户选中的一项改动写进一个 Agent 的配置
API-45 agentLibrary.importSkill(平台宿主命令) 把某个 Agent 的技能或用户选择的目录复制进资源库
API-45 agentLibrary.removeSkill(平台宿主命令) 删除资源库技能,并移除各 Agent 里指向它的链接
API-45 agentSessions.calls(平台宿主命令) 按时间倒序分页列出调用,可按 Agent、会话、时间、模型和成败筛选
API-45 configuration.read(插件函数,清单声明 ID) 报告 files 里的 MCP 服务器、Hooks、Hook 事件和 CLI 自带技能
API-45 configuration.edit(插件函数,清单声明 ID) 把一项改动写进 Core 给的暂存副本

主要改动 / Changes

  • 清单与审查
    • rust/crates/plugin-agents/src/lib.rs:解析并校验 configuration。
      • 三者至少声明一个;路径候选格式同会话来源;files 的 id 唯一。
      • 有 files 就必须有 read,没有 files 时不能有 read,edit 需要 read。
      • 带 read 的 Agent 需要后端和 onAgent:<id>。
      • Agent 目录条目新增 configuration {instructions, skills, files, editable}。
      • sessionRootVariables 也包括配置路径用到的变量。
    • rust/crates/plugin-manifest/src/permissions.rs:新增 agents.configuration。有 configuration 时必须声明,没有时声明即拒绝。
    • 安装审查新增 agentConfiguration 程序,列出全部路径和是否可编辑。
  • 资源库 rust/crates/agent-runtime/src/library.rs(新增)
    • 存放:
      • 目录只允许所有者访问;
      • library.json(服务器、Hooks、指令集);
      • skills/<name>/;
      • state.json(Core 上次写进各 Agent 指令文件的摘要,用来区分“Lithe 写的”和“用户自己写的”);
      • staging/(插件编辑的暂存副本)。
    • read 的修订号是 library.json 的 SHA-256;save 只在修订号未变时替换,从不覆盖读不懂的文件。
    • apply:
      • 指令文件里不是 Lithe 写的文字不会被静默覆盖;
      • 指向别处的配置文件链接,在链接目标处替换;
      • 技能目录里同名但不是链接的条目报 conflict,不覆盖。
    • importSkill:复制时跳过符号链接并回答跳过了哪些。removeSkill:同时移除各 Agent 里指向它的链接。
    • 未授权 agents.configuration 的插件,其 Agent 仍会列出(mayConfigure: false),但从不读取或修改。
    • 新增 agentLibrary.* 错误码,一码一义(逐个列在契约 Agent configuration 一节)。
    • 新增日志事件 agent.library.read_finished、read_failed、updated、change_applied、change_failed、skill_import_finished、skill_removed。只带分类码和计数,不带路径、命令、服务器地址或指令正文。
  • 调用列表 rust/crates/agent-runtime/src/records.rs:agentSessions.calls。超出范围的翻页拒绝为 agentSessions.invalidPage。
  • 命令登记:rust/crates/agent-runtime/src/lib.rs、rust/crates/core/src/protocol/command.rs、rust/crates/core/src/runtime/dispatcher/agents.rs、rust/contracts/rust-core-api.md。
  • 测试
    • agent-runtime 新增 tests/library.rs,共 8 个:
      • library_saves_only_unchanged_revisions_and_only_for_the_user
      • servers_and_hooks_change_only_through_a_checked_staged_copy
      • a_linked_configuration_file_is_replaced_where_it_points
      • instructions_follow_the_library_and_keep_text_lithe_did_not_write
      • skills_are_imported_without_links_and_linked_into_agents
      • agents_without_the_grant_are_listed_but_never_read_or_changed
      • skill_front_matter_and_instruction_text_are_read_as_written
      • malformed_requests_and_a_damaged_library_file_are_refused_each_with_its_own_code
    • records_sync_list_search_read_and_sum_through_the_plugin 覆盖 agentSessions.calls 的筛选、翻页和越界拒绝。
    • plugin-agents 补充配置声明的解析与拒绝用例。
    • core 的 agents_are_reviewed_programs 加上 agentConfiguration 程序。
  • 契约与文档
    • shared/plugins/contract/v1/README.md:新增 Agent configuration 一节(声明、资源库、命令、状态、写回规则、错误码);Backend lifecycle 写明配置文件也由后端服务。
    • plugin-manifest.schema.json:新增 agentConfiguration 定义和 agents.configuration 权限。
    • fixture:
      • agents/agents.plugin.json 补充配置声明;
      • manifest/invalid-manifests.json 新增 10 个拒绝用例;
      • 已有的四个权限列表用例补上新权限。
    • reference/domains/agents.md(中英):新增“资源库:指令、技能、MCP 服务器与 Hooks”一节,并更新权限、激活、审查、SDK 各处。
    • reference/capabilities-and-versions.md、reference/api-catalog.md:写明 0 内补充和旧 Core 的行为。API 总表只改 API-45 的说明行,因为没有新增插件宿主方法。
    • 四种官方 SDK README 新增“Agent configuration functions”一小节,说明用已有的函数注册接口实现 read、edit。SDK 代码不变。
    • reference/protocol-changelog.md:

验证 / Verification

  • cargo test --workspace:全部通过(132 组测试结果,没有失败)。
  • cargo clippy -p lithe-agent-runtime -p lithe-plugin-agents -p lithe-plugin-manifest -p lithe-core --all-targets -- -D warnings、cargo fmt --check:通过。
  • node shared/plugins/scripts/verify-docs.mjs:通过。日志事件目录检查:通过。
  • schema 与 fixture:invalid-manifests.json 的 10 个新用例由 jsonschema 4.25.1 按 draft 2020-12 校验。schema 拒绝其中能表达的部分;“edit 需要 read”等跨字段规则和现有做法一致,只由 Rust 检查。

跟进 / Follow-up

… 0 内补充)

- 清单 agents[] 新增可选 configuration {instructions?, skills?, files?, read?, edit?},新增权限 agents.configuration;
  安装审查新增 agentConfiguration 程序,Agent 目录条目带 configuration 和 mayConfigure
- 新增 agent-runtime library 模块:资源库存放在平台应用数据目录,read 带修订号,save 只在修订号未变时替换,
  apply 把用户选中的一项改动写进一个 Agent(指令文件整份重写、技能用符号链接、MCP 与 Hooks 交给插件 edit 改暂存副本,
  Core 校验后原子替换,期间文件被改动就拒绝);importSkill、removeSkill 管理技能目录
- 新增宿主命令 agentLibrary.configure/read/save/apply/importSkill/removeSkill,写操作只接受用户发起的请求
- 新增 agentLibrary.* 错误码(一码一义)与日志事件 agent.library.*,日志只带分类码和计数
- 契约 README、schema、fixture(agents 插件补配置声明,invalid-manifests 新增 10 个拒绝用例)、
  agents 领域参考、能力版本页、API 总表、四种官方 SDK 说明同步补充
- 协议更新记录:新增本 PR 待合入条目,回填 #220 的合入日期(其余 19 条过期记录见 #222)
@xiaoyumuxi
xiaoyumuxi marked this pull request as ready for review November 28, 2026 16:45
@xiaoyumuxi
xiaoyumuxi merged commit c56ace3 into main Nov 28, 2026
7 of 9 checks passed

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 4 potential issues.

3 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment on lines +1666 to +1667
let bytes = serde_json::to_vec_pretty(&file).map_err(|_| write_failed())?;
write_replacing(&path, &bytes).map_err(|_| write_failed())?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Oversized saves lock the library

When an otherwise valid library serializes past 8 MiB, save writes it and returns success. The same size limit then blocks both reopening the library and saving a smaller replacement.

Learn more

LibraryData::check limits individual entries, not the serialized file. Library::load refuses files over 8 MiB. The revision check uses the same limit, so a smaller replacement is refused too. The user must repair the file outside the library to recover.

Example: A library with 33 instruction sets of 256 KiB each passes the field limits. Its successful save leaves a file that neither read nor save accepts.

Recommended fix: Check the serialized byte length against MAX_LIBRARY_FILE_BYTES before replacing the file. Test that a refused save preserves the prior revision and contents.

Suggested change
let bytes = serde_json::to_vec_pretty(&file).map_err(|_| write_failed())?;
write_replacing(&path, &bytes).map_err(|_| write_failed())?;
let bytes = serde_json::to_vec_pretty(&file).map_err(|_| write_failed())?;
if bytes.len() as u64 > MAX_LIBRARY_FILE_BYTES {
return Err(too_large_file());
}
write_replacing(&path, &bytes).map_err(|_| write_failed())?;

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +2240 to +2243
let mut copied = Copied::default();
let outcome = copy_tree(&source, &partial, 0, &mut copied).and_then(|()| {
let _writing = self.lock_writing();
lithe_platform::entries::rename_no_replace(&partial, &destination).map_err(|error| {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Linked skill manifests vanish on import

When a skill’s SKILL.md is a symlink, import_skill accepts it but copy_tree skips it. The import succeeds, yet the skill stays hidden and blocks another import under the same name.

Learn more

skill_description uses read_bounded, which follows links, so import accepts the source as a skill. copy_tree skips symlinks, including SKILL.md. library_skills then omits the copy because it has no manifest, but the duplicate check still rejects the occupied name.

Example: Import a docs skill whose SKILL.md points to a shared description. The import reports success and one skipped entry, but docs does not appear in the library.

Recommended fix: Preserve the documented no-symlink copy policy. Require a regular SKILL.md in the staged copy before renaming it into the library, and clean up with agentLibrary.notSkill if the manifest is missing.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +857 to +861
let value = value.trim();
if value.starts_with('|') || value.starts_with('>') {
block = Some((key, value.starts_with('>'), Vec::new()));
} else {
values.insert(key, unquote(value));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 YAML comments block skill imports

When SKILL.md has an inline comment after a plain name, front_matter includes the comment in the name. Directory import then rejects the valid skill as having an invalid name.

Learn more

Library::import_skill uses the YAML name for a directory import and falls back to the directory name only when there is no parsed name. A plain YAML scalar ends before a whitespace-separated # comment. The parser retains that comment, so is_skill_name rejects it.

Example: name: docs # Team documentation names the skill docs in YAML. Directory import instead attempts to use docs # Team documentation and returns agentLibrary.invalidSkillName.

Recommended fix: Parse the bounded front matter with a YAML scalar parser, or handle inline comments for plain scalars without treating literal # in quoted scalars as a comment. Add a directory-import test for a commented name.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +1601 to +1605
view.entry["targets"] = json!({
"mcpServers": snapshot.targets.mcp_servers.is_some(),
"hooks": snapshot.targets.hooks.is_some(),
});
view.snapshot = Some(snapshot);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Unresolved configuration appears editable

When a reported target has no resolved path, view still advertises it for MCP servers or hooks. apply_file then rejects the change because there is no file to edit.

Learn more

agent_paths omits a declared file when none of its path candidates resolves. read_snapshot validates returned target IDs against every declaration, so a backend can still report a valid ID for an omitted file. The view advertises the target, and the state maps mark absent items off rather than unsupported. apply_file checks actual resolved paths and refuses to edit the missing target.

Example: main has only a ${env:AGENT_HOME} candidate, and the variable is unset. The plugin reports main as its MCP target, so a library server appears available to turn on, but turning it on returns agentLibrary.noTarget.

Recommended fix: Filter or mask targets without a resolved path before deriving the response’s targets and item states. Keep existing snapshot data readable for the paths that did resolve.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

xiaoyumuxi added a commit that referenced this pull request Nov 28, 2026
* feat(agents): 提示可以带图片,Agent 在清单里声明接受的图片类型(API-45 0 内补充)

清单 agents[].native 新增可选 imageTypes;agents.prompt 新增可选 images [{path}],
Core 按文件开头字节判断类型并检查数量和总大小,didPrompt 带 images [{mimeType, path}]。
四种官方 SDK 新增图片处理方法,没有实现时这一回合以 failed 结束。
更新记录把已合入的 #223 移到 2026-11-28 时间线。

* feat(agents): 提示附件按 ACP 的方式分成图片和文件链接,不限大小

agents.prompt 的 images 改成 attachments:用户选择、粘贴或拖入的文件、文件夹和图片,
最多 64 个,只传路径、不限大小。Core 按文件开头字节把 Agent 在 native.imageTypes
里声明的类型当作图片,其余(含文件夹、空文件、读不了的文件)当作文件链接;
didPrompt 带 {type, path, name, uri, mimeType?}。错误码改为 agents.invalidAttachment、
agents.tooManyAttachments。四种 SDK 改为 prompt_attachments,没有实现时文件链接以
[@name](uri) 并进正文交给 prompt,带图片的回合失败;fixture 补充 Agent plain。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant